/*
 * Copyright 2014 Cungmua, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package cungmua.vn.kiosk.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TabHost;
import cungmua.vn.kiosk.R;
import cungmua.vn.kiosk.db.DatabaseHandler;
import cungmua.vn.kiosk.tabs.BadgeTabManager;
import cungmua.vn.kiosk.tabs.BadgeTabWidget;
import cungmua.vn.kiosk.tabs.TabGroupFourActivity;
import cungmua.vn.kiosk.tabs.TabGroupOneActivity;
import cungmua.vn.kiosk.tabs.TabGroupThreeActivity;
import cungmua.vn.kiosk.tabs.TabGroupTwoActivity;
import cungmua.vn.kiosk.utils.WriteLog;

public class MainActivity extends TabActivity {
	private static TabHost tabHost;
	private DatabaseHandler db;
	Resources res;
	public static MainActivity tabParent;
	/** Called when the activity is first created. */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		db=new DatabaseHandler(this);
		tabParent=this;

		res = getResources(); // Resource object to get Drawables
		TabHost tabHost = getTabHost(); // The activity TabHost
		TabHost.TabSpec spec; // Resusable TabSpec for each tab
		Intent intent; // Reusable Intent for each tab

		//==========================Dang Giao Tabs=============================================
		View tabIndicator_danggian = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator_danggiao, getTabWidget(), false);

		intent = new Intent().setClass(this, TabGroupOneActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		spec = tabHost.newTabSpec("tab1").setIndicator(tabIndicator_danggian)
				.setContent(intent);
		tabHost.addTab(spec);
		//==========================Tra Ve Tabs=============================================
		View tabIndicator_trave = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator_trave, getTabWidget(), false);

		intent = new Intent().setClass(this, TabGroupTwoActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		spec = tabHost.newTabSpec("tab2").setIndicator(tabIndicator_trave)
				.setContent(intent);
		tabHost.addTab(spec);

//		==============================Thong Ke Tab=========================================
		View tabIndicator_thongke = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator_thongke, getTabWidget(), false);

		intent = new Intent().setClass(this, TabGroupThreeActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		spec = tabHost.newTabSpec("tab3").setIndicator(tabIndicator_thongke)
				.setContent(intent);
		tabHost.addTab(spec);
		
		
//		==============================Nhan Vien Tab=========================================
		View tabIndicator_nhanvien = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator_nhanvien, getTabWidget(), false);

		intent = new Intent().setClass(this, TabGroupFourActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		spec = tabHost.newTabSpec("tab4").setIndicator(tabIndicator_nhanvien)
				.setContent(intent);
		tabHost.addTab(spec);
		

		tabHost.setCurrentTab(3);
//		=================================
		
		BadgeTabWidget tabWidget = (BadgeTabWidget)this.findViewById(android.R.id.tabs);
		BadgeTabManager.init(tabWidget);
		
		int index=db.getAllDonHangDangGiao().size();
		BadgeTabManager.getInstance().setBadgeAtIndex(index, 0);
		
	}

	public static TabHost getCurrentTabHost() {
		return tabHost;
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		
	}
}